<?

session_start();

include_once("../classCol.php");

include_once("../helpers/html.php");
include_once("../helpers/CHtml.php");
include_once("../helpers/javascript.php");
include_once("../helpers/CJavascript.php");
include_once("../helpers/Composer.php");
include_once("../helpers/ComposerSourceDb.php");

include_once("controllers/misc.php");
include_once("models/fetchers.php");
include_once("models/handlers.php");

include_once("../models/GHandlers.php");
include_once("../models/handlers.php");
include_once("../models/fetchers.php");
include_once("../models/GFetchers.php");
include_once("../controllers/GlobalProcessors.php");

$stlButton = " ";

/**
 * additional process
 * to reset the tmpJid
 */
$_SESSION["tmpJid"]      = "";

//check what authoration
$UID	=	unserialize($_SESSION["serUID"]);

$thisMdl	 = "PURCHASE";
$mdlNumber = "43";

$srcDbHdr = "USERID_HDR";
$srcDbDtl = "USERID_DTL";

$Misc       = new Misc;
$CHtml      = new CGHtml;
$CJs        = new CGJavascript;
$GProcessors= new GlobalProcessors;
$CFetchers  = new CGFetchers;
$CHandlers  = new CGHandlers;

$CLFetchers = new CLFetchers;
$CLHandlers = new CLHandlers;

$SourceDb   = new Composer;
$SourceDb   = $SourceDb->init("db");

$SourceDb->add("srcDbHdr",            "PCH_HDR");
$SourceDb->add("srcDbDtl",            "PCH_DTL");
$SourceDb->add("srcDbSubDtl",         "PCH_SUB_DTL");
$SourceDb->add("srcDbGroup",          "MST_MODEL_GRP");
$SourceDb->add("srcDbCategory",       "MST_MODEL_CAT");
$SourceDb->add("srcDbModel",          "MST_MODEL");
$SourceDb->add("srcDbSnHdr",          "SN_HDR");
$SourceDb->add("srcDbSnDtl",          "SN_DTL");
$SourceDb->add("srcDbSnSubDtl",       "SN_SUB_DTL");
$SourceDb->add("srcDbTmpDtlDp",       "C_B_DP_SUPP_DTL_TMP");
$SourceDb->add("srcDbTmpSubDp",       "C_B_DP_SUPP_SUB_DTL_TMP");
$SourceDb->add("srcDbDtlDp",          "C_B_DP_SUPP_DTL");
$SourceDb->add("srcDbSubDp",          "C_B_DP_SUPP_SUB_DTL");
$SourceDb->add("srcDbMutIvcSupplier", "MUT_IVC_SUPPLIER");
$SourceDb->add("srcDbMutDp",          "MUT_DP_SUPPLIER");

$check_me_authed          = "NO_OK";
$_SESSION["modify_mode"]  = "N";

$_SESSION["reauthed"] = ($_SESSION["reauthed"] != "")? $_SESSION["reauthed"] : "N";
$_SESSION["recheck"]  = ($_SESSION["recheck"]  != "")? $_SESSION["recheck"]  : "N";

echo  $CJs->includeThis(_TYPE_CSS,"/ecs/myMenu.css");

/**
* Only by pass entry mode and back
* else needs to relogin
*
*/
if($_POST["entry"] ||
   $_POST["back"]  ||
   $_POST["view"]){

  if($_POST["entry"]){

    jumpTo(0,"entry.php");
  }else
  if($_POST["back"]){

    jumpTo(0,"../".$_SESSION["source_caller"]);
  }else
  if($_POST["view"]){

    require("viewdboredit_view.php");
  }else{

    /* Do nothing */
  }
}else{

  if($_SESSION["reauthed"]  == "N" &&
     $_SESSION["recheck"]   == "N"){

    $_SESSION["temp_radioview"] = $_POST["radioview"];
    $_SESSION["temp_selbox"]    = $_POST["selbox"];

    $_SESSION["recheck"] = "Y";

    $flsMessage = "Validity Check";
    $tgtUrl     = "viewdboredit.php";
    $btnLabel   = "Submit";

    $Misc->thisButton($_POST,
                      $btnName,
                      $btnValue);

    $GProcessors->procChkValidation($flsMessage,
                                    $tgtUrl,
                                    $btnLabel,
                                    $btnName,
                                    $btnValue,
                                    $stlButton);
  }else
  if($_SESSION["reauthed"]  == "N" &&
     $_SESSION["recheck"]   == "Y"){

    $Db = new oracleDb;

    $Db->init($_SESSION["ORCLU"],
              $_SESSION["OPASS"],
              $_SESSION["SID"],
              _NO_COMMENT);

    if($Db->connect()){

      $Misc->fetchRelogin($Db,
                          $_POST["reauth_user"],
                          $_POST["reauth_pass"],
                          $_SESSION["company"],
                          $srcDbHdr,
                          $nrows,
                          $_SESSION["user_id_reauth"]);

      if($nrows > 0 ){

        $mode = $Misc->thisMode($_POST);

        if($UID->getPrivsByNumber( $mdlNumber, $mode) > 0){

          $_SESSION["reauthed"] = "Y";

          $flsMessage = "Login Ok";
          $tgtUrl     = "viewdboredit.php";
          $btnLabel   = "Continue";

          $Misc->thisButton($_POST,
                            $btnName,
                            $btnValue);

          $GProcessors->formOkValidated($flsMessage,
                                        $tgtUrl,
                                        $btnLabel,
                                        $btnName,
                                        $btnValue,
                                        $stlButton);

        }else{

          unset($_SESSION["reauthed"]);
          unset($_SESSION["recheck"]);

          $Misc->usrError("Authed Error reason : ".$chk_res." ");
        }
      }else{

        $Db->dc();

        $_SESSION["recheck"] = "Y";
        $flsMessage = "Validity Check";
        $tgtUrl     = "viewdboredit.php";
        $btnLabel   = "Submit";

        $Misc->thisButton($_POST,
                          $btnName,
                          $btnValue);

        $GProcessors->procChkValidation($flsMessage,
                                        $tgtUrl,
                                        $btnLabel,
                                        $btnName,
                                        $btnValue,
                                        $stlButton);
      }
    }else{

      $Misc->usrDieJs(_DB_CONN_ERROR);
    }
  }else
  if($_SESSION["reauthed"]  == "Y" &&
     $_SESSION["recheck"]   == "Y"){

    unset($_SESSION["reauthed"]);
    unset($_SESSION["recheck"]);

    $check_me_authed = "OK";

    if($_POST["modify"]){

      if($_POST["radioview"] == ''){

        $_POST["radioview"] = $_SESSION["temp_radioview"] ;
      }

      require("viewdboredit_modify.php");
    }else
    if($_POST["delete"]){

      $_POST["selbox"] = $_SESSION["temp_selbox"] ;

      require("viewdboredit_delete.php");
    }else
    if($_POST["approve"]){

      $_POST["selbox"] = $_SESSION["temp_selbox"] ;

      require("viewdboredit_approve.php");
    }else
    if($_POST["cancel"]){

      $_POST["selbox"] = $_SESSION["temp_selbox"] ;

      require("viewdboredit_cancel.php");
    }else{

      /* DO nothing */
    }
  }else{

    $_SESSION["recheck"] = "Y";

    $flsMessage = "Validity Check";
    $tgtUrl     = "viewdboredit.php";
    $btnLabel   = "Submit";

    $Misc->thisButton($_POST,
                      $btnName,
                      $btnValue);

    $GProcessors->procChkValidation($flsMessage,
                                    $tgtUrl,
                                    $btnLabel,
                                    $btnName,
                                    $btnValue,
                                    $stlButton);
  }
}
?>